<template>
  <view>
    <el-table v-loading="loading" :data="data" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" width="100" />
      <el-table-column label="公告标题" align="center" prop="title" :show-overflow-tooltip="true" />
      <el-table-column label="类型" align="center" prop="type" width="100">
        <template #default="scope">
          <scope-tag :dict="notice_type_dict" :value="scope.row.type"></scope-tag>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" width="100">
        <template #default="scope">
          <scope-tag :dict="status_dict" :value="scope.row.status"></scope-tag>
        </template>
      </el-table-column>
      <!-- <el-table-column label="创建者" align="center" prop="createBy" width="100" /> -->
      <el-table-column label="创建时间" align="center" prop="createdTime" width="180"> </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button
            size="mini"
            type="text"
            icon="Edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:notice:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="Delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:notice:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </view>
</template>
<script setup>
import ScopeTag from "../../../components/ScopeTag/index.vue";
import { status_dict, notice_type_dict } from "@/constant/dict";
import { inject } from "vue";

const $ = inject("$");
const queryOne = inject("queryOne");
const deleteOne = inject("deleteOne");
// 定义可更新数据
const emit = defineEmits(["success",'update:ids']);

const props = defineProps({
  data: {
    type: Array,
  },
  loading: {
    type: Boolean,
    value: false,
  },
  ids:{
    type:Array
  }
});
const { proxy } = getCurrentInstance();

// 多条选择
function handleSelectionChange(selection) {
  let t = selection.map((item) => item.id);
  emit('update:ids',t)
}
// 点击删除
function handleDelete(row) {
  proxy.$modal.confirm('是否确认删除编号为"' + row.id + '"的数据项?').then(function () {
    deleteOne(row.id).then((res) => {
      emit("success");
      proxy.$modal.msgSuccess("删除成功");
    });
  });
}
// 更新
function handleUpdate(row) {
  //console.log(row.id)
  queryOne(row.id).then((res) => {
    console.log(res);
    $.value.doUpdate(res);
  });
}
</script>
